<!--
 * @Author       : wfl
 * @LastEditors  : wfl
 * @description  :
 * @updateInfo   :
 * @Date         : 2022-11-14 15:08:44
 * @LastEditTime : 2023-06-28 09:43:13
-->
<script lang="ts" setup name="IkPersonSelect">
import { ref } from 'vue'
import { userApi } from '@/MainApp/apis/user'

defineProps({
  title: {
    type: String,
    default: '选择用户'
  },
  multiple: {
    type: Boolean,
    default: true
  },
  placeholder: {
    type: String,
    default: '请选择或模糊搜索'
  }
})

const value = defineModel({
  type: String,
  default: ''
})

const { msgError } = useMessage()

const personList = ref([])
const handPersons = async () => {
  const { msg, success, data } = await userApi.getAllUser()
  if (success) {
    personList.value = data
      ? data.map((v: { name: string; id: string; }) => {
        return {
          label: v.name,
          value: v.id
        }
      })
      : []
  }
  else { msgError(msg) }
}
handPersons()
</script>

<template>
  <el-select-v2
    v-model="value"
    :attrs="$attrs"
    filterable
    :options="personList"
    :placeholder="placeholder"
    class="w-full"
    :multiple="multiple"
  />
</template>
